home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 4
/
Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso
/
Development
/
General
/
MacMETH3.2.1 Folder
/
MacMETH3.2.1 Disk 2⁄2
/
More Examples
/
Hennessy4.MOD
< prev
next >
Wrap
Text File
|
1994-03-21
|
4KB
|
213 lines
MODULE Hennessy4;
FROM Storage IMPORT ALLOCATE;
FROM SYSTEM IMPORT VAL, TSIZE;
FROM SYSTEM IMPORT REG, SETREG;
FROM InOut IMPORT WriteLn, WriteString, WriteInt, Read, OpenOutput, CloseOutput;
CONST
fftbase = 0.0 (* 1.11 *);
fpfftbase = 4.44;
(* fft *)
fftsize = 256;
fftsize2 = 129;
TYPE
(* FFT *)
complex = RECORD
rp, ip: REAL
END;
carray = ARRAY [0..fftsize+1] OF complex ;
c2array = ARRAY [0..fftsize2+1] OF complex ;
Proc = PROCEDURE;
VAR
fixed,floated: REAL; ch: CHAR;
(* FFT *)
z, w: carray;
e: c2array;
zr, zi: REAL;
(* global *)
seed: LONGINT;
(* global procedures *)
PROCEDURE Getclock (): LONGINT;
TYPE P = POINTER TO LONGINT;
VAR ticks: P; tk: LONGINT;
BEGIN ticks := VAL(P, 16AH);
tk := ticks^; RETURN TRUNCD(FLOATD(tk) * (1000.0D0/60.0D0) + 0.5D0)
END Getclock;
PROCEDURE Initrand ();
BEGIN seed := 74755D
END Initrand;
PROCEDURE Rand (): LONGINT;
BEGIN
seed := (seed * 1309D + 13849D) MOD 65535D;
RETURN (seed);
END Rand;
PROCEDURE Cos (x: REAL): REAL;
(* computes cos of x (x in radians) by an expansion *)
VAR i, factor: LONGINT;
result,power: REAL;
BEGIN
result := 1.0; factor := 1D; power := x; i := 2;
WHILE i <= 10D DO
factor := factor * i; power := power*x;
IF i MOD 2D = 0D THEN
IF i MOD 4D = 0D THEN result := result + power/FLOAT(factor)
ELSE result := result - power/FLOAT(factor)
END
END;
INC(i)
END ;
RETURN result
END Cos;
PROCEDURE Min0( arg1, arg2: LONGINT): LONGINT;
BEGIN
IF arg1 < arg2 THEN RETURN arg1
ELSE RETURN arg2
END
END Min0;
PROCEDURE Uniform11(VAR iy: LONGINT; VAR yfl: REAL);
BEGIN
iy := (4855D*iy + 1731D) MOD 8192D;
yfl := FLOAT(iy)/8192.0;
END Uniform11;
PROCEDURE Exptab(n: LONGINT; VAR e: c2array);
VAR theta, divisor: REAL; h: ARRAY [0..26] OF REAL;
i, j, k, l, m: LONGINT;
BEGIN
theta := 3.1415926536;
divisor := 4.0; i:=1D;
WHILE i <= 25D DO
h[i] := 1.0/(2.0*Cos( theta/divisor ));
divisor := divisor + divisor;
INC(i)
END;
m := n DIV 2D ;
l := m DIV 2D ;
j := 1D ;
e[1].rp := 1.0 ;
e[1].ip := 0.0;
e[l+1D].rp := 0.0;
e[l+1D].ip := 1.0 ;
e[m+1D].rp := -1.0 ;
e[m+1D].ip := 0.0 ;
REPEAT
i := l DIV 2D ;
k := i ;
REPEAT
e[k+1D].rp := h[j]*(e[k+i+1D].rp+e[k-i+1D].rp) ;
e[k+1D].ip := h[j]*(e[k+i+1D].ip+e[k-i+1D].ip) ;
k := k+l ;
UNTIL ( k > m );
j := Min0( j+1D, 25);
l := i ;
UNTIL ( l <= 1D );
END Exptab;
PROCEDURE Fft( n: LONGINT; VAR z, w: carray; VAR e: c2array; sqrinv: REAL);
VAR i, j, k, l, m, index: LONGINT; h: REAL;
BEGIN
m := n DIV 2D ;
l := 1 ;
REPEAT
k := 0D ;
j := l ;
i := 1D ;
REPEAT
REPEAT
w[i+k].rp := z[i].rp+z[m+i].rp ;
w[i+k].ip := z[i].ip+z[m+i].ip ;
h := e[k+1D].rp*(z[i].rp-z[i+m].rp);
w[i+j].rp := h-e[k+1D].ip*(z[i].ip-z[i+m].ip) ;
h := e[k+1D].rp*(z[i].ip-z[i+m].ip);
w[i+j].ip := h+e[k+1D].ip*(z[i].rp-z[i+m].rp) ;
i := i+1D ;
UNTIL ( i > j );
k := j ;
j := k+l ;
UNTIL ( j > m );
(*z := w ;*) index := 1D;
REPEAT
z[index] := w[index];
index := index+1D;
UNTIL ( index > n );
l := l+l ;
UNTIL ( l > m );
i := 1;
WHILE i <= n DO
z[i].rp := sqrinv*z[i].rp ;
z[i].ip := -sqrinv*z[i].ip;
INC(i)
END
END Fft;
PROCEDURE Oscar ();
VAR i: LONGINT;
BEGIN
Exptab(fftsize,e) ;
seed := 5767 ; i := 1D;
WHILE i <= LONG(fftsize) DO
Uniform11( seed, zr );
Uniform11( seed, zi );
z[i].rp := 20.0*zr - 10.0;
z[i].ip := 20.0*zi - 10.0;
INC(i)
END ;
i := 1;
WHILE i <= 20D DO Fft(fftsize,z,w,e,0.0625); INC(i) END
END Oscar;
PROCEDURE Time(s: ARRAY OF CHAR; p: Proc; base, fbase: REAL);
VAR timer: LONGINT;
BEGIN
timer := Getclock();
p;
timer := Getclock()-timer;
WriteString(s);
WriteInt(SHORT(timer), 8); WriteLn;
fixed := fixed + FLOAT(timer)*base;
floated := floated + FLOAT(timer)*fbase
END Time;
PROCEDURE main2(i: INTEGER);
BEGIN
fixed := 0.0; floated := 0.0;
Time("FFT ", Oscar, fftbase, fpfftbase);
END main2;
PROCEDURE main;
BEGIN
fixed := 0.0; floated := 0.0;
Time("FFT ", Oscar, fftbase, fpfftbase);
WriteLn;
main2(19);
END main;
BEGIN Initrand;
OpenOutput("H4.Mac");
WriteString("Hennessy4 mit MacMETH 3.2 : "); WriteLn;
WriteLn;
main;
CloseOutput;
WriteLn;
WriteString("any key to terminate. "); WriteLn;
Read(ch);
END Hennessy4.